package com.gitee.smsdistribution.controller;

import com.gitee.smsdistribution.common_response.ResponseResultBody;
import com.gitee.smsdistribution.model.SendWay;
import com.gitee.smsdistribution.model.SmsInfo;
import com.gitee.smsdistribution.service.SmsInfoService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@ResponseResultBody
@AllArgsConstructor
@RestController
@RequestMapping("/sms-info")
public class SmsInfoController {

    private final SmsInfoService smsInfoService;

    @PostMapping("/send-sms")
    public void sendSms(@RequestBody List<Long> ids,
                        @Parameter(description = "群发渠道") @RequestParam SendWay sendWay) throws Exception {
        smsInfoService.sendSms(ids, sendWay);
    }

    @PostMapping
    public List<SmsInfo> addSmsInfo(@Valid @RequestBody List<SmsInfo> smsInfos) {
        return smsInfoService.addSmsInfo(smsInfos);
    }

    @GetMapping
    public Page<SmsInfo> pageList(@RequestParam String keyword,
                                  @RequestParam(required = false) Date startDate,
                                  @RequestParam(required = false) Date endDate,
                                  @RequestParam(defaultValue = "0") int pageNumber,
                                  @RequestParam(defaultValue = "10") int pageSize) {
        return smsInfoService.pageList(keyword, startDate, endDate, pageNumber, pageSize);
    }

}
